package com.avic.rong.goodsSort.activity.secondListActivity;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.goodsSort.CarView;
import com.avic.rong.goodsSort.activity.GoodsSortActivity;
import com.avic.rong.goodsSort.activity.MaxRecyclerView;
import com.avic.rong.goodsSort.adapter.drawerAdapter.GoodsSortGjDrawerPlatformCarrierAdapter;
import com.avic.rong.goodsSort.adapter.drawerAdapter.GoodsSortGjDrawerPriceMianYiAdapter;
import com.avic.rong.goodsSort.adapter.drawerAdapter.GoodsSortGjDrawerRJCPAdapter;
import com.avic.rong.goodsSort.adapter.drawerAdapter.GoodsSortGjDrawerUsageModeAdapter;
import com.avic.rong.goodsSort.adapter.drawerAdapter.GoodsSortGjDrawerUseTimeAdapter;
import com.avic.rong.goodsSort.adapter.drawerAdapter.GoodsSortGjDrawerVersionInformationAdapter;
import com.avic.rong.goodsSort.adapter.secondListAdapter.GoodsSortGjShowRvAdapter;
import com.avic.rong.goodsSort.adapter.secondListAdapter.GoodsSortGjShowSxRvAdapter;
import com.avic.rong.goodsSort.adapter.secondListAdapter.GoodsSortGjShowTimeRvAdapter;
import com.avic.rong.goodsSort.api.drawerApi.GoodsSortGjDrawerApi;
import com.avic.rong.goodsSort.api.secondListApi.GoodsSortSearchAllGjApi;
import com.avic.rong.goodsSort.api.secondListApi.GoodsSortSearchAllGjSxApi;
import com.avic.rong.goodsSort.api.secondListApi.GoodsSortSearchAllGjTimeApi;
import com.avic.rong.goodsSort.bean.secondDrawerBean.GoodsSortGjDrawerBean;
import com.avic.rong.goodsSort.bean.secondDrawerBean.GoodsSortGjDrawerOtherBean;
import com.avic.rong.goodsSort.bean.showRvBean.GoodsSortSearchAllGjBean;
import com.avic.rong.shoppingCar.activity.ShoppingCarActivity;
import com.avic.rong.shoppingCar.api.ShoppingCarListApi;
import com.avic.rong.shoppingCar.bean.ShoppingCarListBean;
import com.avic.rong.userOrder.api.AddCarApi;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.DeviceUtils;
import com.avic.rong.utils.EditUtils;
import com.avic.rong.utils.SharedPreferencesUtil;
import com.avic.rong.utils.ToastTools;
import com.avic.rong.wedgit.loadingLayout.LoadingLayout;
import com.example.minato.minastore.BaseResultEntity;
import com.example.minato.minastore.http.HttpManager;
import com.example.minato.minastore.listener.HttpOnNextListener;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GoodsSortGjActivity extends BaseActivity implements View.OnClickListener, GoodsSortGjDrawerRJCPAdapter.GoodsSortGjDrawerRJCPListener, GoodsSortGjDrawerUsageModeAdapter.GoodsSortGjDrawerUsageModeListener
        , GoodsSortGjDrawerVersionInformationAdapter.GoodsSortGjDrawerVersionInformationListener, GoodsSortGjDrawerUseTimeAdapter.GoodsSortGjDrawerUseTimeListener, GoodsSortGjDrawerPriceMianYiAdapter.GoodsSortGjDrawerPriceMianYiListener
        , GoodsSortGjDrawerPlatformCarrierAdapter.GoodsSortGjDrawerPlatformCarrierListener, GoodsSortGjShowRvAdapter.GoodsGjListener, GoodsSortGjShowSxRvAdapter.GoodsGjSxListener {


    @BindView(R.id.goods_sort_gj_back)
    ImageView goodsSortGjBack;
    @BindView(R.id.goods_sort_gj_fenlei)
    ImageView goodsSortGjFenlei;
    @BindView(R.id.goods_sort_gj_edit)
    EditText goodsSortGjEdit;
    @BindView(R.id.goods_sort_gj_title)
    RelativeLayout goodsSortGjTitle;
    @BindView(R.id.goods_sort_gj_zh)
    RadioButton goodsSortGjZh;
    @BindView(R.id.goods_sort_gj_time)
    RadioButton goodsSortGjTime;
    @BindView(R.id.goods_sort_gj_hot)
    RadioButton goodsSortGjHot;
    @BindView(R.id.goods_sort_gj_shaixuan)
    RadioButton goodsSortGjShaixuan;
    @BindView(R.id.goods_sort_bz_sort)
    LinearLayout goodsSortBzSort;
    @BindView(R.id.goods_sort_gj_fenge)
    View goodsSortGjFenge;
    @BindView(R.id.goods_sort_gj_Rv)
    MaxRecyclerView goodsSortGjRv;
    @BindView(R.id.goods_sort_gj_drawer_ruanjianchanpin_rv)
    RecyclerView goodsSortGjDrawerRuanjianchanpinRv;
    @BindView(R.id.goods_sort_gj_drawer_shiyongfangshi_rv)
    RecyclerView goodsSortGjDrawerShiyongfangshiRv;
    @BindView(R.id.goods_sort_gj_drawer_banbenxinxi_rv)
    RecyclerView goodsSortGjDrawerBanbenxinxiRv;
    @BindView(R.id.goods_sort_gj_drawer_shiyongshixiao_rv)
    RecyclerView goodsSortGjDrawerShiyongshixiaoRv;
    @BindView(R.id.goods_sort_gj_drawer_jiagemianyi_rv)
    RecyclerView goodsSortGjDrawerJiagemianyiRv;
    @BindView(R.id.goods_sort_gj_drawer_Reset)
    TextView goodsSortGjDrawerReset;
    @BindView(R.id.goods_sort_gj_drawer_Sure)
    TextView goodsSortGjDrawerSure;
    @BindView(R.id.goods_sort_gj_drawer)
    ConstraintLayout goodsSortGjDrawer;
    @BindView(R.id.goods_sort_gj_DrawerLayout)
    DrawerLayout goodsSortGjDrawerLayout;
    @BindView(R.id.goods_sort_gj_drawer_pingtaizaiti_rv)
    RecyclerView goodsSortGjDrawerPingtaizaitiRv;
    @BindView(R.id.search_gj_SmartRefreshLayout)
    SmartRefreshLayout searchGjSmartRefreshLayout;
    @BindView(R.id.goods_sort_gj_LoadingLayout)
    LoadingLayout goodsSortGjLoadingLayout;
    private GoodsSortGjShowRvAdapter showRvAdapter;
    private GoodsSortGjShowSxRvAdapter showSxRvAdapter;
    private GoodsSortGjShowTimeRvAdapter showTimeRvAdapter;
    private List<GoodsSortSearchAllGjBean.DataBean> gjBeanList = new ArrayList<>();
    private List<GoodsSortSearchAllGjBean.DataBean> gjSxBeanList = new ArrayList<>();
    private List<GoodsSortSearchAllGjBean.DataBean> gjTimeBeanList = new ArrayList<>();

    //使用方式
    private List<GoodsSortGjDrawerOtherBean> usageModeList = new ArrayList<>();
    //版本信息
    private List<GoodsSortGjDrawerOtherBean> versionInformationList = new ArrayList<>();
    //使用时效
    private List<GoodsSortGjDrawerOtherBean> useTimeList = new ArrayList<>();
    //价格面议
    private List<GoodsSortGjDrawerOtherBean> priceNegotiableList = new ArrayList<>();
    //平台载体
    private List<GoodsSortGjDrawerOtherBean> platformCarrierList = new ArrayList<>();
    //软件产品
    private List<GoodsSortGjDrawerBean.CategoryBean.SubCategoryBean> subCategoryBeanList = new ArrayList<>();

    private GoodsSortGjDrawerRJCPAdapter rjcpAdapter;
    private GoodsSortGjDrawerUsageModeAdapter usageModeAdapter;
    private GoodsSortGjDrawerUseTimeAdapter useTimeAdapter;
    private GoodsSortGjDrawerPriceMianYiAdapter priceMianYiAdapter;
    private GoodsSortGjDrawerVersionInformationAdapter versionInformationAdapter;
    private GoodsSortGjDrawerPlatformCarrierAdapter platformCarrierAdapter;

    private boolean timeFlag = false;
    private CarView carView;
    private TextView carTv;
    private String keyword;
    private GoodsSortSearchAllGjApi searchAllApi;
    private int pageNo = 1;
    private int REFFRSH = 0;
    private GoodsSortSearchAllGjTimeApi searchAllTimeApi;
    private GoodsSortSearchAllGjSxApi searchAllSXApi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_goods_sort_gj);
        ButterKnife.bind(this);
        carView = new CarView(this);
        carTv = carView.findViewById(R.id.car_number);
        Intent intent = getIntent();
        keyword = intent.getStringExtra("keyword");
        goodsSortGjEdit.setText(keyword);
        goodsSortGjRv.setNestedScrollingEnabled(false);
        goodsSortGjDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        goodsSortGjZh.setSelected(true);
        showRvAdapter = new GoodsSortGjShowRvAdapter(GoodsSortGjActivity.this);
        goodsSortGjRv.setLayoutManager(new LinearLayoutManager(GoodsSortGjActivity.this));
        showTimeRvAdapter = new GoodsSortGjShowTimeRvAdapter(GoodsSortGjActivity.this);
        goodsSortGjRv.setLayoutManager(new LinearLayoutManager(GoodsSortGjActivity.this));
        showSxRvAdapter = new GoodsSortGjShowSxRvAdapter(GoodsSortGjActivity.this);
        initListener();
        initDrawData();


        //加载购物车商品数量
        loadData();
        initData(keyword);
        setAdapter();
        carView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(GoodsSortGjActivity.this, ShoppingCarActivity.class);
                startActivity(intent);
            }
        });
        carView.show();
        goodsSortGjLoadingLayout.setOnReloadListener(new LoadingLayout.OnReloadListener() {
            @Override
            public void onReload(View v) {
                HttpManager.getInstance().doHttpDeal(searchAllApi);
                goodsSortGjLoadingLayout.setStatus(LoadingLayout.LOADING);
            }

            @Override
            public void onReturn(View v) {
                onBackPressed();
            }
        });
        goodsSortGjLoadingLayout.setStatus(LoadingLayout.LOADING);
    }

    private void setAdapter() {
        //软件产品
        GridLayoutManager rjcpManager = new GridLayoutManager(this, 3);
        goodsSortGjDrawerRuanjianchanpinRv.setLayoutManager(rjcpManager);
        rjcpAdapter = new GoodsSortGjDrawerRJCPAdapter(GoodsSortGjActivity.this);
        goodsSortGjDrawerRuanjianchanpinRv.setAdapter(rjcpAdapter);
        //使用方式
        GridLayoutManager usageModeManager = new GridLayoutManager(this, 3);
        goodsSortGjDrawerShiyongfangshiRv.setLayoutManager(usageModeManager);
        usageModeAdapter = new GoodsSortGjDrawerUsageModeAdapter(this);
        goodsSortGjDrawerShiyongfangshiRv.setAdapter(usageModeAdapter);
        //版本信息
        GridLayoutManager versionInformationManager = new GridLayoutManager(this, 3);
        goodsSortGjDrawerBanbenxinxiRv.setLayoutManager(versionInformationManager);
        versionInformationAdapter = new GoodsSortGjDrawerVersionInformationAdapter(this);
        goodsSortGjDrawerBanbenxinxiRv.setAdapter(versionInformationAdapter);
        //使用时效
        GridLayoutManager useTimeManager = new GridLayoutManager(this, 3);
        goodsSortGjDrawerShiyongshixiaoRv.setLayoutManager(useTimeManager);
        useTimeAdapter = new GoodsSortGjDrawerUseTimeAdapter(this);
        goodsSortGjDrawerShiyongshixiaoRv.setAdapter(useTimeAdapter);
        //价格面议
        GridLayoutManager priceNegotiableManager = new GridLayoutManager(this, 3);
        goodsSortGjDrawerJiagemianyiRv.setLayoutManager(priceNegotiableManager);
        priceMianYiAdapter = new GoodsSortGjDrawerPriceMianYiAdapter(this);
        goodsSortGjDrawerJiagemianyiRv.setAdapter(priceMianYiAdapter);
        //平台载体
//        GridLayoutManager platformCarrierManager = new GridLayoutManager(this, 3);
        goodsSortGjDrawerPingtaizaitiRv.setLayoutManager(new LinearLayoutManager(this));
        platformCarrierAdapter = new GoodsSortGjDrawerPlatformCarrierAdapter(this);
        goodsSortGjDrawerPingtaizaitiRv.setAdapter(platformCarrierAdapter);

        rjcpAdapter.setGoodsSortGjDrawerRJCPListener(this);
        usageModeAdapter.setGoodsSortGjDrawerUsageModeListener(this);
        useTimeAdapter.setGoodsSortGjDrawerUseTimeListener(this);
        priceMianYiAdapter.setGoodsSortGjDrawerPriceMianYiListener(this);
        versionInformationAdapter.setGoodsSortGjDrawerVersionInformationListener(this);
        platformCarrierAdapter.setGoodsSortGjDrawerPriceMianYiListener(this);
    }

    @Override
    protected void onResume() {
        loadData();
        super.onResume();
    }

    private void initListener() {
        goodsSortGjZh.setOnClickListener(this);
        goodsSortGjTime.setOnClickListener(this);
        goodsSortGjHot.setOnClickListener(this);
        goodsSortGjShaixuan.setOnClickListener(this);

        goodsSortGjBack.setOnClickListener(this);
        goodsSortGjFenlei.setOnClickListener(this);

        goodsSortGjDrawerReset.setOnClickListener(this);
        goodsSortGjDrawerSure.setOnClickListener(this);

        goodsSortGjEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    //关闭软键盘
                    EditUtils.showORhideSoftKeyboard(GoodsSortGjActivity.this);
                    keyword = goodsSortGjEdit.getText().toString();
                    gjBeanList.clear();
                    goodsSortGjZh.setSelected(true);
                    goodsSortGjTime.setSelected(false);
                    goodsSortGjHot.setSelected(false);
                    goodsSortGjShaixuan.setSelected(false);
                    initData(keyword);
                    showRvAdapter.notifyDataSetChanged();
                    return true;
                }
                return false;
            }
        });
        searchGjSmartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                pageNo = 1;
                setAllBeanListClear();
                switch (REFFRSH){
                    case 1:
                        initData(keyword);
                        break;
                    case 2:
                        initGjTimeData(keyword,1);
                        break;
                    case 3:
                        initGjSureData();
                        break;
                }
                searchGjSmartRefreshLayout.finishRefresh(1000);
            }
        });
        searchGjSmartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                ++pageNo;
                switch (REFFRSH){
                    case 1:
                        searchAllApi.setPageNo(pageNo);
                        HttpManager.getInstance().doHttpDeal(searchAllApi);
                        break;
                    case 2:
                        searchAllTimeApi.setSort(1);
                        HttpManager.getInstance().doHttpDeal(searchAllTimeApi);
                        break;
                    case 3:
                        Map<String, String> gjNowShuXing = getGjNowShuXing();
                        String attrPro = gjNowShuXing.get("attrPro");
                        searchAllSXApi.setAttrPro(attrPro);
                        HttpManager.getInstance().doHttpDeal(searchAllSXApi);
                        break;
                }
                searchGjSmartRefreshLayout.finishLoadMore(1000);
            }
        });
    }

    @Override
    protected int getContentViewId() {
        return 0;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void addListener() {

    }

    private void setSortTimeDrawable(int p) {
        Drawable downTime = getResources().getDrawable(p);
        downTime.setBounds(0, 0, downTime.getMinimumWidth(), downTime.getMinimumHeight());
        goodsSortGjTime.setCompoundDrawables(null, null, downTime, null);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.goods_sort_gj_back:
                finish();
                break;
            case R.id.goods_sort_gj_fenlei:
                Intent intent = new Intent(this, GoodsSortActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.goods_sort_gj_zh:

                goodsSortGjZh.setSelected(true);
                goodsSortGjTime.setSelected(false);
                goodsSortGjHot.setSelected(false);
                goodsSortGjShaixuan.setSelected(false);
                setSortTimeDrawable(R.mipmap.goods_sort_time_sort);
                initData(keyword);
                break;
            case R.id.goods_sort_gj_time:

                goodsSortGjZh.setSelected(false);
                goodsSortGjTime.setSelected(true);
                goodsSortGjHot.setSelected(false);
                goodsSortGjShaixuan.setSelected(false);
                if (timeFlag) {
                    setSortTimeDrawable(R.mipmap.down_time_sort2x);
                    initGjTimeData(keyword,0);
                } else {
                    setSortTimeDrawable(R.mipmap.up_time_sort2x);
                    initGjTimeData(keyword,1);
                }
                timeFlag = !timeFlag;
                break;
            case R.id.goods_sort_gj_hot:

                goodsSortGjZh.setSelected(false);
                goodsSortGjTime.setSelected(false);
                goodsSortGjHot.setSelected(true);
                goodsSortGjShaixuan.setSelected(false);
                setSortTimeDrawable(R.mipmap.goods_sort_time_sort);
                initData(keyword);
                break;
            case R.id.goods_sort_gj_shaixuan:
//                setAllDrawerListClear();
                goodsSortGjZh.setSelected(false);
                goodsSortGjTime.setSelected(false);
                goodsSortGjHot.setSelected(false);
                goodsSortGjShaixuan.setSelected(true);
                setSortTimeDrawable(R.mipmap.goods_sort_time_sort);
                goodsSortGjDrawerLayout.openDrawer(GravityCompat.END);
                break;
            case R.id.goods_sort_gj_drawer_Reset:
                setReset();
                break;
            case R.id.goods_sort_gj_drawer_Sure:
                initGjSureData();
                goodsSortGjDrawerLayout.closeDrawer(GravityCompat.END);
                break;
        }
    }

    private void initGjTimeData(String keyword, int i) {
        REFFRSH=2;
        goodsSortGjRv.setAdapter(showTimeRvAdapter);
        searchAllTimeApi = new GoodsSortSearchAllGjTimeApi(this, searchAll1Listener, 2, 459,i);
        searchAllTimeApi.setCache(false);
        HttpManager.getInstance().doHttpDeal(searchAllTimeApi);
    }

    HttpOnNextListener<BaseResultEntity> searchAll1Listener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (!subjects.getCode().equals("200")) {
                ToastTools.showToast(GoodsSortGjActivity.this, subjects.getMsg());
                Log.e("cjx", "软件工具数据：" + subjects.getMsg());
                return;
            }
            ArrayList<GoodsSortSearchAllGjBean> gjBeans = (ArrayList<GoodsSortSearchAllGjBean>) subjects.getData();
            gjTimeBeanList.addAll(gjBeans.get(1).getData());
            showTimeRvAdapter.setBeanList(gjTimeBeanList);
            goodsSortGjLoadingLayout.setStatus(LoadingLayout.SUCCESS);
        }

        @Override
        public void onCacheNext(String cache) {
        }

        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", "软件工具数据" + e.getMessage());
            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
                goodsSortGjLoadingLayout.setStatus(LoadingLayout.NO_NETWORK);
            } else {
                goodsSortGjLoadingLayout.setStatus(LoadingLayout.ERROR);
            }
        }
    };


    private void setAllDrawerListClear() {
        useTimeList.clear();
        usageModeList.clear();
        versionInformationList.clear();
        priceNegotiableList.clear();
        subCategoryBeanList.clear();
        platformCarrierList.clear();
    }

    private void setAllBeanListClear() {
        gjBeanList.clear();
        gjSxBeanList.clear();
        gjTimeBeanList.clear();
    }

    //获取软件工具数据监听
    private void initData(String keyword) {
        REFFRSH=1;
        goodsSortGjRv.setAdapter(showRvAdapter);
        searchAllApi = new GoodsSortSearchAllGjApi(this, searchAllListener, 2, 459,pageNo,10);
        searchAllApi.setCache(false);
        HttpManager.getInstance().doHttpDeal(searchAllApi);
    }

    HttpOnNextListener<BaseResultEntity> searchAllListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (!subjects.getCode().equals("200")) {
                ToastTools.showToast(GoodsSortGjActivity.this, subjects.getMsg());
                Log.e("cjx", "软件工具数据：" + subjects.getMsg());
                return;
            }
            ArrayList<GoodsSortSearchAllGjBean> gjBeans = (ArrayList<GoodsSortSearchAllGjBean>) subjects.getData();
            gjBeanList.addAll(gjBeans.get(1).getData());
            showRvAdapter.setGoodsGjListener(GoodsSortGjActivity.this);
            showRvAdapter.setBeanList(gjBeanList);
            goodsSortGjLoadingLayout.setStatus(LoadingLayout.SUCCESS);
        }

        @Override
        public void onCacheNext(String cache) {
        }

        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", "软件工具数据" + e.getMessage());
            if (e instanceof SocketTimeoutException || e instanceof ConnectException) {
                goodsSortGjLoadingLayout.setStatus(LoadingLayout.NO_NETWORK);
            } else {
                goodsSortGjLoadingLayout.setStatus(LoadingLayout.ERROR);
            }
        }
    };

    //获取软件工具属性数据监听
    private void initDrawData() {
        GoodsSortGjDrawerApi wdDrawerApi = new GoodsSortGjDrawerApi(this, drawerBeanListener);
        wdDrawerApi.setCache(false);
        HttpManager.getInstance().doHttpDeal(wdDrawerApi);
    }

    HttpOnNextListener<BaseResultEntity> drawerBeanListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (!subjects.getCode().equals("200")) {
                ToastTools.showToast(GoodsSortGjActivity.this, subjects.getMsg());
                Log.e("cjx", "软件工具属性数据：" + subjects.getMsg());
                return;
            }
            GoodsSortGjDrawerBean gjDrawerBean = (GoodsSortGjDrawerBean) subjects.getData();
            List<GoodsSortGjDrawerBean.AllAttrBean> allAttrBeanList = gjDrawerBean.getAllAttr();
            //软件产品
            subCategoryBeanList.addAll(gjDrawerBean.getCategory().get(0).getSubCategory());
            rjcpAdapter.setCategoryBeanList(subCategoryBeanList);
            //使用方式
            for (int n = 0; n < allAttrBeanList.get(0).getAttrValues().size(); n++) {
                int typeId = allAttrBeanList.get(0).getTypeId();
                String attrValue = allAttrBeanList.get(0).getAttrValues().get(n);
                GoodsSortGjDrawerOtherBean bean = new GoodsSortGjDrawerOtherBean(typeId, attrValue, false);
                usageModeList.add(bean);
            }
            Log.e("cjx", "usageModeList:" + usageModeList.size());
            //版本信息
            for (int k = 0; k < allAttrBeanList.get(1).getAttrValues().size(); k++) {
                int typeId = allAttrBeanList.get(1).getTypeId();
                String attrValue = allAttrBeanList.get(1).getAttrValues().get(k);
                GoodsSortGjDrawerOtherBean bean = new GoodsSortGjDrawerOtherBean(typeId, attrValue, false);
                versionInformationList.add(bean);
            }
            Log.e("cjx", "versionInformationList:" + versionInformationList.size());
            //使用时效
            for (int j = 0; j < allAttrBeanList.get(2).getAttrValues().size(); j++) {
                int typeId = allAttrBeanList.get(2).getTypeId();
                String attrValue = allAttrBeanList.get(2).getAttrValues().get(j);
                GoodsSortGjDrawerOtherBean bean = new GoodsSortGjDrawerOtherBean(typeId, attrValue, false);
                useTimeList.add(bean);
            }
            Log.e("cjx", "useTimeList:" + useTimeList.size());
            //价格面议
            for (int i = 0; i < allAttrBeanList.get(4).getAttrValues().size(); i++) {
                int typeId = allAttrBeanList.get(4).getTypeId();
                String attrValue = allAttrBeanList.get(4).getAttrValues().get(i);
                GoodsSortGjDrawerOtherBean bean = new GoodsSortGjDrawerOtherBean(typeId, attrValue, false);
                priceNegotiableList.add(bean);
            }
            Log.e("cjx", "priceNegotiableList:" + priceNegotiableList.size());
            //平台载体
            for (int y = 0; y < allAttrBeanList.get(3).getAttrValues().size(); y++) {
                int typeId = allAttrBeanList.get(3).getTypeId();
                String attrValue = allAttrBeanList.get(3).getAttrValues().get(y);
                GoodsSortGjDrawerOtherBean bean = new GoodsSortGjDrawerOtherBean(typeId, attrValue, false);
                platformCarrierList.add(bean);
            }
            Log.e("cjx", "platformCarrierList:" + platformCarrierList.size());

            priceMianYiAdapter.setPriceMianYiList(priceNegotiableList);
            usageModeAdapter.setUsageModeList(usageModeList);
            useTimeAdapter.setUseTimeList(useTimeList);
            versionInformationAdapter.setVersionInformationList(versionInformationList);
            platformCarrierAdapter.setPlatformCarrierList(platformCarrierList);
        }

        @Override
        public void onCacheNext(String cache) {
        }

        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", "软件工具属性数据" + e.getMessage());
        }
    };

    //软件产品
    @Override
    public void setRJCPSelected(int index) {
        for (int i = 0; i < subCategoryBeanList.size(); i++) {
            if (i == index) {
                subCategoryBeanList.get(i).setSelected(!subCategoryBeanList.get(i).isSelected());
            } else {
                subCategoryBeanList.get(i).setSelected(false);
            }
        }
        rjcpAdapter.notifyDataSetChanged();
    }

    //使用方式
    @Override
    public void setUsageModeListSelected(int index) {
        for (int i = 0; i < usageModeList.size(); i++) {
            if (i == index) {
                usageModeList.get(i).setSelected(!usageModeList.get(i).isSelected());
            } else {
                usageModeList.get(i).setSelected(false);
            }
        }
        usageModeAdapter.notifyDataSetChanged();
    }

    //版本信息
    @Override
    public void setVersionInformationListSelected(int index) {
        for (int i = 0; i < versionInformationList.size(); i++) {
            if (i == index) {
                versionInformationList.get(i).setSelected(!versionInformationList.get(i).isSelected());
            } else {
                versionInformationList.get(i).setSelected(false);
            }
        }
        versionInformationAdapter.notifyDataSetChanged();
    }

    //使用时效
    @Override
    public void setUseTimeSelected(int index) {
        for (int i = 0; i < useTimeList.size(); i++) {
            if (i == index) {
                useTimeList.get(i).setSelected(!useTimeList.get(i).isSelected());
            } else {
                useTimeList.get(i).setSelected(false);
            }
        }
        useTimeAdapter.notifyDataSetChanged();
    }

    //价格面议
    @Override
    public void setPriceMianYiListSelected(int index) {
        for (int i = 0; i < priceNegotiableList.size(); i++) {
            if (i == index) {
                priceNegotiableList.get(i).setSelected(!priceNegotiableList.get(i).isSelected());
            } else {
                priceNegotiableList.get(i).setSelected(false);
            }
        }
        priceMianYiAdapter.notifyDataSetChanged();
    }

    @Override
    public void setPlatformCarrierListSelected(int index) {
        for (int i = 0; i < platformCarrierList.size(); i++) {
            if (i == index) {
                platformCarrierList.get(i).setSelected(!platformCarrierList.get(i).isSelected());
            } else {
                platformCarrierList.get(i).setSelected(false);
            }
        }
        platformCarrierAdapter.notifyDataSetChanged();
    }

    private void setReset() {
        for (int i = 0; i < platformCarrierList.size(); i++) {
            platformCarrierList.get(i).setSelected(false);
        }
        platformCarrierAdapter.notifyDataSetChanged();

        for (int i = 0; i < priceNegotiableList.size(); i++) {
            priceNegotiableList.get(i).setSelected(false);
        }
        priceMianYiAdapter.notifyDataSetChanged();

        for (int i = 0; i < useTimeList.size(); i++) {
            useTimeList.get(i).setSelected(false);
        }
        useTimeAdapter.notifyDataSetChanged();

        for (int i = 0; i < versionInformationList.size(); i++) {
            versionInformationList.get(i).setSelected(false);
        }
        versionInformationAdapter.notifyDataSetChanged();

        for (int i = 0; i < usageModeList.size(); i++) {
            usageModeList.get(i).setSelected(false);
        }
        usageModeAdapter.notifyDataSetChanged();

        for (int i = 0; i < subCategoryBeanList.size(); i++) {
            subCategoryBeanList.get(i).setSelected(false);
        }
        rjcpAdapter.notifyDataSetChanged();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        carView.destory();
    }

    //获取购物车列表数据
    private void loadData() {
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            final ShoppingCarListApi shoppingCarListApi = new ShoppingCarListApi(this, simpleOnNextListener, SharedPreferencesUtil.getLoginToken(), DeviceUtils.getIMEString(GoodsSortGjActivity.this));
            shoppingCarListApi.setCache(false);
            HttpManager.getInstance().doHttpDeal(shoppingCarListApi);
        }else {
            final ShoppingCarListApi shoppingCarListApi = new ShoppingCarListApi(this, simpleOnNextListener, "", DeviceUtils.getIMEString(GoodsSortGjActivity.this));
            shoppingCarListApi.setCache(false);
            HttpManager.getInstance().doHttpDeal(shoppingCarListApi);
        }
    }

    //获取购物车列表数据监听
    HttpOnNextListener simpleOnNextListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(GoodsSortGjActivity.this, subjects.getMsg());
                Log.e("cjx", subjects.getMsg());
                return;
            }
            ShoppingCarListBean bean = (ShoppingCarListBean) subjects.getData();
            int size = bean.getCartList().size();
            int num=0;
            for (int i = 0; i < size; i++) {
                int goodsNumber = bean.getCartList().get(i).getGoodsNumber();
                num+=goodsNumber;
            }
            Log.e("cjx", "初始数量：" + size + "");
            carTv.setText(num + "");
        }

        @Override
        public void onCacheNext(String cache) {
        }

        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", "Bz购物车列表数据：" + e.getMessage());
        }
    };

    @Override
    public void addGjCar(String skuStr) {
        AddGjCar(skuStr);
    }

    private void AddGjCar(String skuStr) {
        Log.e("cjx", "skuStr:" + skuStr);
        if (!getSharedPreferencesUtil().getLogintoken().isEmpty()) {
            Map<String, String> map = new HashMap<>();
            map.put("skuStr", skuStr);
            map.put("orderType", 4 + "");
//            是否再次购买（0/1）
            map.put("buyAgain", 0 + "");
            map.put("token", getSharedPreferencesUtil().getLogintoken());
            map.put("deviceId", DeviceUtils.getIMEString(context));
            final AddCarApi addCarApi = new AddCarApi(GoodsSortGjActivity.this, simpleOnNextListenerAddCar);
            addCarApi.setCache(false);
            addCarApi.setMap(map);
            HttpManager.getInstance().doHttpDeal(addCarApi);
        }
    }

    //添加购物车
    HttpOnNextListener simpleOnNextListenerAddCar = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {

            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(context, subjects.getMsg());
                return;
            }
            double currentCarNumber = (double) subjects.getData();
            Log.e("cjx", "currentCarNumber:" + currentCarNumber + "");
            int i = (int) currentCarNumber;
            carTv.setText(i + "");
//            View toastView = LayoutInflater.from(GoodsSortBzActivity.this).inflate(R.layout.toast_addcar_success,null);
//            ToastTools.showToast(context,"加入购物车成功！");
            ToastTools.showToast("");
        }


        @Override
        public void onCacheNext(String cache) {
        }

        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", e.getMessage());
        }
    };

    private void initGjSureData() {
        REFFRSH=3;
        goodsSortGjRv.setAdapter(showSxRvAdapter);
        Map<String, String> gjNowShuXing = getGjNowShuXing();
        String s = gjNowShuXing.get("nowTypeId");
        int nowTypeId = Integer.parseInt(s);
        String attrPro = gjNowShuXing.get("attrPro");
        Log.e("cjx", "Gj__nowTypeId:" + nowTypeId);
        Log.e("cjx", "Gj__nowattrPro:" + attrPro);
        searchAllSXApi = new GoodsSortSearchAllGjSxApi(this, searchAllSxListener, 2, nowTypeId, attrPro);
        searchAllSXApi.setCache(false);
        HttpManager.getInstance().doHttpDeal(searchAllSXApi);
    }

    HttpOnNextListener<BaseResultEntity> searchAllSxListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (!subjects.getCode().equals("200")) {
                ToastTools.showToast(GoodsSortGjActivity.this, subjects.getMsg());
                return;
            }
            ArrayList<GoodsSortSearchAllGjBean> gjBeans = (ArrayList<GoodsSortSearchAllGjBean>) subjects.getData();
            gjSxBeanList.addAll(gjBeans.get(1).getData());
            showSxRvAdapter.setGoodsGjSxListener(GoodsSortGjActivity.this);
            showSxRvAdapter.setGjSxBeanList(gjSxBeanList);
            showSxRvAdapter.notifyDataSetChanged();
        }

        @Override
        public void onCacheNext(String cache) {
        }

        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", "软件工具数据" + e.getMessage());
        }
    };

    private Map<String, String> getGjNowShuXing() {
        Map<String, String> map = new HashMap<>();
        int nowTypeId = 459;
        map.put("nowTypeId", nowTypeId + "");
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < subCategoryBeanList.size(); i++) {
            if (subCategoryBeanList.get(i).isSelected()) {
                map.put("nowTypeId", subCategoryBeanList.get(i).getCatId() + "");
            }
        }
        for (int i = 0; i < usageModeList.size(); i++) {
            if (usageModeList.get(i).isSelected()) {
                sb.append("&29__" + usageModeList.get(i).getAttrValue());
            }
        }
        for (int i = 0; i < versionInformationList.size(); i++) {
            if (versionInformationList.get(i).isSelected()) {
                sb.append("&30__" + versionInformationList.get(i).getAttrValue());
            }
        }
        for (int i = 0; i < platformCarrierList.size(); i++) {
            if (platformCarrierList.get(i).isSelected()) {
                sb.append("&32__" + platformCarrierList.get(i).getAttrValue());
            }
        }
        for (int i = 0; i < priceNegotiableList.size(); i++) {
            if (priceNegotiableList.get(i).isSelected()) {
                sb.append("&181__" + priceNegotiableList.get(i).getAttrValue());
            }
        }
        for (int i = 0; i < useTimeList.size(); i++) {
            if (useTimeList.get(i).isSelected()) {
                if (useTimeList.get(i).getAttrValue().equals("一个月")) {
                    sb.append("&31__一个月");
                } else if (useTimeList.get(i).getAttrValue().equals("三个月")) {
                    sb.append("&31__三个月");
                } else if (useTimeList.get(i).getAttrValue().equals("永久")) {
                    sb.append("&31__永久");
                } else if (useTimeList.get(i).getAttrValue().equals("一年")) {
                    sb.append("&31__一年");
                } else if (useTimeList.get(i).getAttrValue().equals("一次")) {
                    sb.append("&31__一次");
                }
            }
        }
        map.put("attrPro", sb.toString());
        return map;
    }

    @Override
    public void addGjSxCar(String skuStr) {
        AddGjCar(skuStr);
    }



    public static Intent getIntent(Context context, String catName){
        Intent intent = new Intent(context, GoodsSortGjActivity.class);
        intent.putExtra("keyword", catName);
        return intent;
    }

}
